package com.qfedu.provider.lisenter;

import com.qfedu.config.RocketmqConfig;
import com.qfedu.provider.entity.DbUser;
import com.qfedu.provider.entity.DbUserDetail;
import com.qfedu.provider.mapper.DbUserDetailMapper;
import com.qfedu.provider.mapper.DbUserMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * @author Administrator
 * @date 2024/11/24 下午2:56
 */
@Component
@RequiredArgsConstructor
@Slf4j
@RocketMQMessageListener(topic = RocketmqConfig.TOPIC_REGISTER, consumerGroup = "register_group")
public class RegisterRocketMq implements RocketMQListener<Integer> {
    private final DbUserMapper dbUserMapper;
    private final DbUserDetailMapper dbUserDetailMapper;


    @Override
    public void onMessage(Integer message) {
        log.info("开始处理新用户注册-奖励-{}" + message);
        System.out.println("注册成功" + message);
        DbUser dbUser = dbUserMapper.selectById(message);
        if (dbUser == null) {
            System.out.println("用户不存在,不存在详情");
            return;
        }
        DbUserDetail dbUserDetail = new DbUserDetail(dbUser.getId(), dbUser.getNickName());
        dbUserDetailMapper.insert(dbUserDetail);
    }
}
